package top.lshaci.learning.hutool;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.symmetric.AES;

import java.util.ArrayList;
import java.util.List;

/**
 * RsaTest
 *
 * @author liangxu
 */
public class RsaTest {

    public static void main(String[] args) {
        String publicKeyBase64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOGl2qCa5CSpG6aVyqkp05WXp/T6+dUGaePEEuUXSpGC52V56djae0/gWb36XOwi03vvFp6frgtfGgm9ZXOxlepgfJSxtgslq2HZv7mtHElnMGghhNEB29jS5Lt3W1pQsEyyOojoblYppBEQYem2n4KSpCzHgMLfwKHvf/nekEkQIDAQAB";
        String privateKeyBase64 = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAI4aXaoJrkJKkbppXKqSnTlZen9Pr51QZp48QS5RdKkYLnZXnp2Np7T+BZvfpc7CLTe+8Wnp+uC18aCb1lc7GV6mB8lLG2CyWrYdm/ua0cSWcwaCGE0QHb2NLku3dbWlCwTLI6iOhuVimkERBh6bafgpKkLMeAwt/Aoe9/+d6QSRAgMBAAECgYBcs2SA5XnRcxXoFo3GFIkOfYnE/bXhmS6ocURQNAE3wjelKfmmbF+IWeJM0jQ3UkLvR9fzMRlheC/dh2vnUf104TEHb4wiPSH3u10QBCgAR6I/hLXPXu5rW1mXHOwUvQry9tmwGSjFNPYnx2HFTdku7wEFb1reXTzHIZDZJ3BHJQJBAMYhAa/P/8TCXw3ZQtEt0p5eHUDVlLr/HTCAZttUmhlp4LSMhhSZ6Kx9EQwIK6xzTDY/Ermb2eTi0rbK2YmxBI8CQQC3nAwTGkRsl0NY86cM3DwTylrnu9q9jLGoCwhiB3tC0ZOxDk/UVOMAQoL48OpLk0MbHZpnfbcdN+uLXH2aJzTfAkEAwq+ARtAuVZthZ+xLGdzbDz8Po7u7kBxLBHPHnlH9smc1pHRI9ElgNs4WSCpnL+eDxfIoZjZc3+p6f5/ILuLAxQJAUnrG8c3a7u0EU/EgGabVVg6Qx4ibuop5RAOwwFicBmge8Gp9ceSwFG3MaAfROCHvAz9JHTRcDcQRC4mA4r66AQJBAIn8xJ4EsZeE4Gfz0Cb8YTrg2kotcrK++8n+hs1pWoqBEb4H4QcaDJT85/6cMPuGuyQ9pL/H1lWl7NbvdjD7xSc=";
        RSA rsa = SecureUtil.rsa(privateKeyBase64, publicKeyBase64);
        System.err.println(rsa.encryptBase64("123456", KeyType.PublicKey));
        System.err.println(rsa.encryptBase64("123456", KeyType.PublicKey));
        System.err.println(rsa.encryptBcd("123456", KeyType.PublicKey));

        String rsaEncrypt = "RymZMa8Q07OGPv+LoOVycQuI2iMyXcuALdbAoFgNjI3lmeVAf28PYXSPexUgdQGtE8FakyBAmbwI2IMH6d24+3+PIGj4QaKNH+rt6MrBikQoJRsRU1hX1Tcyn5m5iUTOBwgm0d8MQ7dZsRkDL5kaq6+mvl9mIZ7bRRFfMnnYzjA=";
        System.err.println(rsa.decryptStr(rsaEncrypt, KeyType.PrivateKey));

        AES aes = SecureUtil.aes();
        System.err.println(aes.encryptBase64("123456"));
        System.err.println(aes.encryptBase64("123456"));
        System.err.println(aes.encryptBase64("123456"));

        List<Dto> list = new ArrayList<>();
        Dto reduce = list.stream().reduce(Dto.zero(), Dto::add);
    }

    static class Dto {
        int a;
        int b;
        int c;

        public static Dto zero() {
            Dto dto = new Dto();
            dto.a = 0;
            dto.b = 0;
            return dto;
        }

        public static Dto add(Dto a, Dto b) {
            Dto dto = new Dto();
            dto.a = a.a + b.a;
            dto.b = a.b + b.b;
            return dto;
        }
    }
}


